let express = require('express')
let router = express.Router()

router.get('/:newsname', async (req,res,next)=>{

  //1.整理参数
  let {_limit,_page,q,_sort} = req.query
  let collectionName = req.params.newsname

  //2.兜库
  try{
    let result = await req.mgdb.findList({
      collectionName,_limit,_page,q,_sort
    })
    res.send(result)
  }catch(e){
    res.send(e)
  }
})

router.get('/:newsname/:_id', async (req,res,next)=>{
  //1.整理参数
  let collectionName = req.params.newsname
  let _id = req.params._id

  //2.兜库
  try{
    let result = await req.mgdb.findDetail({
      collectionName,_id
    })
    res.send(result)
  }catch(e){
    res.send(e)
  }
})
module.exports=router;